﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;
using System.Data;


namespace DAO
{
    public class KhachHangDAO
    {
        public int CapNhatDiemTichLuy(int MaKH, int Diem)
        {
            int flag = -1;
            SqlConnection conn = null;
            //SqlDataReader reader = null;

            try
            {
                // doc diem tich luy
                int diemtl;
                String sql = "select DiemTichLuy from KhachHang where MaKH = " + MaKH;
                conn = DataProvider.ConnectDB();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = sql;
                cmd = new SqlCommand(sql, conn);
                diemtl = Convert.ToInt32(cmd.ExecuteScalar());
                diemtl += Diem;
                // cap nhat diem
                sql = "Update KhachHang set DiemTichLuy = " + diemtl + " where MaKH = " + MaKH ;
                cmd = new SqlCommand(sql, conn);
                cmd.ExecuteNonQuery();

                flag = 1;

            }
            catch (Exception ex)
            { String e = ex.ToString(); }
            finally
            { conn.Close(); }
            return flag;
        }
    }
}
